package com.allwees.bs.task.order.flow;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author Daniel
 * @Version 1.0.0
 * @Description
 * @CreateTime 2020/11/2 10:31
 */
@Configuration
public class ThreadPoolConfig {

    static final int CONCURRENCY = 100;

    @Bean("awsThreadPool")
    public ExecutorService buildConsumerQueueThreadPool(){
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("aws-thread-%d").build();
        return new ThreadPoolExecutor(CONCURRENCY, CONCURRENCY, 0L, TimeUnit.SECONDS,
                new SynchronousQueue<>(),namedThreadFactory,new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
